package com.sn.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sn.core.component.page.Pagination;
import com.sn.core.emums.SexEnum;
import com.sn.core.emums.SrcTypeEnum;
import com.sn.core.util.EnumUtil;
import com.sn.dao.ScoreMapper;
import com.sn.model.CustomerScore;
import com.sn.model.CustomerScoreLog;
import com.sn.model.req.CustomerScoreLogReq;
import com.sn.model.req.CustomerScoreReq;
import com.sn.model.vo.CustomerScoreLogVo;
import com.sn.model.vo.CustomerScoreVo;
import com.sn.model.vo.CustomerVo;
import com.sn.service.CustomerScoreService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.ws.ServiceMode;
import java.util.List;

/**
 * Created by qingshengzheng on 18/6/21.
 */
@Service
public class CustomerScoreServiceImpl implements CustomerScoreService {
    @Autowired
    private ScoreMapper scoreMapper;

    public void addCustomerScoreLog(CustomerScoreLog log) {
        scoreMapper.addScoreLog(log);

    }

    public Pagination queryCustomerScoreLog(CustomerScoreLogReq req) {
        Pagination pagination = new Pagination(req.getPageno(), req.getPagesize());
        Page<?> page = PageHelper.offsetPage(pagination.getStart(), pagination.getPageSize());
        List<CustomerScoreLogVo> vos = scoreMapper.queryScoreLogs(req);
        for(CustomerScoreLogVo vo:vos){
            vo.setSrctypedesc(StringUtils.isBlank(vo.getSrctype() + "") ? "" : EnumUtil.getByCode(SrcTypeEnum.class, vo.getSrctype()+"").getDesc());
        }
        pagination.setTotalCount(page.getTotal());
        pagination.setV(vos);
        return pagination;
    }

    public Pagination queryScores(CustomerScoreReq req) {
        Pagination pagination = new Pagination(req.getPageno(), req.getPagesize());
        Page<?> page = PageHelper.offsetPage(pagination.getStart(), pagination.getPageSize());
        List<CustomerScoreVo> vos = scoreMapper.queryScores(req);
        pagination.setTotalCount(page.getTotal());
        pagination.setV(vos);
        return pagination;
    }

    public void addCustomerScore(CustomerScore customerScore) {
        scoreMapper.addScore(customerScore);

    }

    public void updateCustomerScore(CustomerScore customerScore) {

    }

    public void increaseCustomerScore(CustomerScore customerScore) {
        scoreMapper.increaseScore(customerScore);

    }

    public CustomerScoreVo scoreDetail(Long cid) {
        return null;
    }
}
